<template>
<!-- 生命体征(已取消) -->
    <div >
        <div class="header">
            <div class="header-left" @click="finish"><image :src="titleUrl" class="header-left-img"></image></div>
            <div class="header-center"><text class="header-text">体格检查</text></div>
            <div class="header-right" @click="save" v-if="canSave"><text class="header-right-text">保存</text></div>
            <div class="header-right-s" v-if="! canSave"></div>
        </div>
        <div class="content">
            <div class="box">
                <div class="title"><text class="box-text">意识:</text></div>
                <div class="checkbox" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='清醒'?'box-active':'']" @click="ISChecked('EmergenModel','CONSCIOUSNESS_TYPE','清醒')"><text class="checkbox-text" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='清醒'?'box-text-active':'']">清醒</text></div>
                <div class="checkbox mf-10" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='对语言有反应'?'box-active':'']" @click="ISChecked('EmergenModel','CONSCIOUSNESS_TYPE','对语言有反应')"><text class="checkbox-text" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='对语言有反应'?'box-text-active':'']">对语言有反应</text></div>
                <div class="checkbox mf-10" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='对刺痛有反应'?'box-active':'']" @click="ISChecked('EmergenModel','CONSCIOUSNESS_TYPE','对刺痛有反应')"><text class="checkbox-text" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='对刺痛有反应'?'box-text-active':'']">对刺痛有反应</text></div>
                <div class="checkbox-auto mf-10" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='对任何刺激都无反应'?'box-active':'']" @click="ISChecked('EmergenModel','CONSCIOUSNESS_TYPE','对任何刺激都无反应')"><text class="checkbox-text" :class="[resData.EmergenModel.CONSCIOUSNESS_TYPE==='对任何刺激都无反应'?'box-text-active':'']">对任何刺激都无反应</text></div>
            </div>
            <div class="box">
                <div class="line">
                    <div class="title"><text class="box-text">体格检查:</text></div>
                </div>
            </div>
            <div class="box">
                <div class="line">
                    <div class="title"><text class="box-text">呼吸:</text></div>
                    <div class="input">
                        <input type="tel" class="input-text" v-model="resData.EmergenModel.RESPIRATION_RATE" v-if="canSave"></input>
                        <text type="tel" class="input-text" v-if="! canSave">{{resData.EmergenModel.RESPIRATION_RATE}}</text>
                        <text class="input-unit">次 / 分</text>
                    </div>
                </div>
                <div class="line">
                    <div class="title"><text class="box-text">脉搏:</text></div>
                    <div class="input">
                        <input type="tel" class="input-text" v-model="resData.EmergenModel.PULSE_RATE" v-if="canSave"></input>
                        <text type="tel" class="input-text" v-if="! canSave">{{resData.EmergenModel.PULSE_RATE}}</text>
                        <text class="input-unit">次 / 分</text>
                    </div>
                </div>
            </div>
            <div class="box">
                <div class="line">
                    <div class="title"><text class="box-text">心率:</text></div>
                    <div class="input">
                        <input type="tel" class="input-text" v-model="resData.EmergenModel.HEART_RATE" v-if="canSave"></input>
                        <text type="tel" class="input-text" v-if="! canSave">{{resData.EmergenModel.HEART_RATE}}</text>
                        <text class="input-unit">次 / 分</text>
                    </div>
                </div>
                <div class="line">
                    <div class="title"><text class="box-text">血压:</text></div>
                    <div class="input">
                        <input type="tel" class="input-text" v-model="resData.EmergenModel.BLOOD_PRESSURE" v-if="canSave"></input>
                        <text type="tel" class="input-text" v-if="! canSave">{{resData.EmergenModel.BLOOD_PRESSURE}}</text>
                        <text class="input-unit">mmHg</text>
                    </div>
                </div>
            </div>
            <div class="box">
                <div class="line">
                    <div class="title"><text class="box-text">Killip分级:</text></div>
                    <div class="input" @click="IS_KILLIP_LEVEL=!IS_KILLIP_LEVEL" v-if="canSave">
                        <text class="input-text">{{resData.EmergenModel.KILLIP_LEVEL}}</text>
                        <image :src="imgUrl" class="img-unit"></image>
                    </div>
                    <div class="input" v-if="! canSave">
                        <text class="input-text">{{resData.EmergenModel.KILLIP_LEVEL}}</text>
                        <image :src="imgUrl" class="img-unit"></image>
                    </div>
                </div>
                <div class="line">
                    <div class="title"><text class="box-text">SPO2:</text></div>
                    <div class="input">
                        <input type="text" class="input-text" v-model="resData.EmergenModel.scen_spo2" v-if="canSave"></input>
                        <text type="text" class="input-text" v-if="! canSave">{{resData.EmergenModel.scen_spo2}}</text>
                        <text class="input-unit">%</text>
                    </div>
                </div>
            </div>
            <div class="box" v-if="IS_KILLIP_LEVEL && canSave">
                <div class="title"></div>
                <div class="checkbox" :class="[resData.EmergenModel.KILLIP_LEVEL==='I级(no CHF)'?'box-active':'']" @click="resData.EmergenModel.KILLIP_LEVEL='I级(no CHF)',IS_KILLIP_LEVEL=false"><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='I级(no CHF)'?'box-text-active':'']">I级(no CHF)</text></div>
                <div class="checkbox-auto mf-10" :class="[resData.EmergenModel.KILLIP_LEVEL==='II级(rales and/or JVD)'?'box-active':'']" @click="resData.EmergenModel.KILLIP_LEVEL='II级(rales and/or JVD)',IS_KILLIP_LEVEL=false"><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='II级(rales and/or JVD)'?'box-text-active':'']">II级(rales and/or JVD)</text></div>
                <div class="checkbox-auto mf-10" :class="[resData.EmergenModel.KILLIP_LEVEL==='III级(pulmonary edema)'?'box-active':'']" @click="resData.EmergenModel.KILLIP_LEVEL='III级(pulmonary edema)',IS_KILLIP_LEVEL=false"><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='III级(pulmonary edema)'?'box-text-active':'']">III级(pulmonary edema)</text></div>
                <div class="checkbox-auto mf-10" :class="[resData.EmergenModel.KILLIP_LEVEL==='IV级(cardiogenic shock)'?'box-active':'']" @click="resData.EmergenModel.KILLIP_LEVEL='IV级(cardiogenic shock)',IS_KILLIP_LEVEL=false"><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='IV级(cardiogenic shock)'?'box-text-active':'']">IV级(cardiogenic shock)</text></div>
            </div>
            <div class="box" v-if="IS_KILLIP_LEVEL && ! canSave">
                <div class="title"></div>
                <div class="checkbox" :class="[resData.EmergenModel.KILLIP_LEVEL==='I级(no CHF)'?'box-active':'']" ><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='I级(no CHF)'?'box-text-active':'']">I级(no CHF)</text></div>
                <div class="checkbox-auto mf-10" :class="[resData.EmergenModel.KILLIP_LEVEL==='II级(rales and/or JVD)'?'box-active':'']" ><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='II级(rales and/or JVD)'?'box-text-active':'']">II级(rales and/or JVD)</text></div>
                <div class="checkbox-auto mf-10" :class="[resData.EmergenModel.KILLIP_LEVEL==='III级(pulmonary edema)'?'box-active':'']" ><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='III级(pulmonary edema)'?'box-text-active':'']">III级(pulmonary edema)</text></div>
                <div class="checkbox-auto mf-10" :class="[resData.EmergenModel.KILLIP_LEVEL==='IV级(cardiogenic shock)'?'box-active':'']"><text class="checkbox-text" :class="[resData.EmergenModel.KILLIP_LEVEL==='IV级(cardiogenic shock)'?'box-text-active':'']">IV级(cardiogenic shock)</text></div>
            </div>
            <div class="box">
                <div class="line">
                    <div class="title"><text class="box-text">瞳孔左:</text></div>
                    <div class="input">
                        <input type="text" class="input-text" v-model="resData.EmergenModel.scen_pupil_l" v-if="canSave"></input>
                        <text type="text" class="input-text" v-if="! canSave">{{resData.EmergenModel.scen_pupil_l}}</text>
                        <text class="input-unit">mm</text>
                    </div>
                </div>
                <div class="line">
                    <div class="title"><text class="box-text">瞳孔右:</text></div>
                    <div class="input">
                        <input type="text" class="input-text" v-model="resData.EmergenModel.scen_pupil_r" v-if="canSave"></input>
                        <text type="text" class="input-text" v-if="! canSave">{{resData.EmergenModel.scen_pupil_r}}</text>
                        <text class="input-unit">mm</text>
                    </div>
                </div>
            </div>
            <div class="box">
                <div class="line">
                    <div class="title"><text class="box-text">其他:</text></div>
                    <input type="text" class="textarea" v-model="resData.EmergenModel.else" v-if="canSave"></input>
                    <text type="text" class="textarea" v-if="! canSave">{{resData.EmergenModel.else}}</text>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import WeexNativeModule from "../../common/WeexNativeModule"
    import DateUtil from "../../common/util/DateUtil"
    import StringUtils from "../../common/util/StringUtils"
    import JsonFilter from "../../common/util/JsonFilter"
    import ACApi from "../../common/http/ACApi"
    import Resource from "../../../dist/res/Resource"
    export default {
        name: 'EMNewMainEditInfo',
        data: function () {   
            return {
                currentTab: 0,
                titleUrl: 'title_cha_img.png',
                imgUrl: 'choose.png',
                IS_KILLIP_LEVEL: false,
                info: {
                    orgCode: '',
                    doctorId: '',
                    doctor: '',
                    orderId: '',
                    pid: '',
                    id: ''
                },
                resData: {
                    EmergenModel: {
                        id:"",
                        CONSCIOUSNESS_TYPE: '',
                        RESPIRATION_RATE: '',
                        PULSE_RATE: '',
                        HEART_RATE: '',
                        BLOOD_PRESSURE: '',
                        KILLIP_LEVEL: '',
                        scen_pupil_l: '', //瞳孔左
                        scen_pupil_r: '', //瞳孔右
                        scen_spo2: '',      //SPO2
                        else: '', //其他
                    }
                },
                canSave:true
            }         
                                            
        },
        mounted: function() {
            let _this = this
            WeexNativeModule.showProgressDialog('请稍等')
            WeexNativeModule.getLoginUser(function (data) {
                let loginUser = JSON.parse(data.loginUser)
                _this.info.orgCode = loginUser.orgid
                _this.info.doctorId = loginUser.id
                _this.info.doctor = loginUser.username               
            })
            WeexNativeModule.getParam(function (data) {
                let param = JSON.parse(data.param)
//                WeexNativeModule.alert(param)
                if(param.isJustOpen){
                    _this.canSave = false;
                    let data = JSON.parse(param.data);
                    let content = JSON.parse(data.content);
                    _this.resData.EmergenModel.CONSCIOUSNESS_TYPE = content.CONSCIOUSNESS_TYPE;
                    _this.resData.EmergenModel.RESPIRATION_RATE = content.RESPIRATION_RATE;
                    _this.resData.EmergenModel.PULSE_RATE = content.PULSE_RATE;
                    _this.resData.EmergenModel.HEART_RATE = content.HEART_RATE;
                    _this.resData.EmergenModel.BLOOD_PRESSURE = content.BLOOD_PRESSURE;
                    _this.resData.EmergenModel.KILLIP_LEVEL = content.KILLIP_LEVEL;
                    _this.resData.EmergenModel.scen_pupil_l = content.scen_pupil_l;
                    _this.resData.EmergenModel.scen_pupil_r = content.scen_pupil_r;
                    _this.resData.EmergenModel.scen_spo2 = content.scen_spo2;
                    _this.resData.EmergenModel.else = content.else;
                }else {
                    _this.canSave = true;
                    _this.info.orderId = param.taskcode
                    _this.info.pid = param.pid
                }
            })
        },
        methods: {
            finish: function() {
                WeexNativeModule.finish()
            },
            ISChecked: function (model,key,value) {
                if(! this.canSave){
                    return
                }
                this.resData[model][key] = this.resData[model][key] && this.resData[model][key] == value  ? '' : value
            },

            save: function() {
                if(! this.canSave){
                    return
                }
                let _this = this;
                let json = JsonFilter.filter(_this.resData.EmergenModel);
                let postjson = {
                    'content': JSON.stringify(json),
                    'doctor': _this.info.doctor,
                    'doctorId': _this.info.doctorId,
                    'orderId': _this.info.orderId,
                    'orgCode': _this.info.orgCode,
                    'pid': _this.info.pid,
                };
                WeexNativeModule.addEMNode(postjson)
            }
        }
    }
</script>
<style>
    .header {
        height: 40px;
        background-color: #FFF;
        display: flex;
        flex-direction: row;
        justify-content: space-between;    
        align-items: center;
        border-bottom-style: solid;
        border-bottom-width: 0.5px;
        border-bottom-color: #f2f2f2;
    }
    .header-left {
        width: 40px;
        height: 40px;
        justify-content: center;
        align-items: center;
    }
    .header-left-img {
        width: 30px;
        height: 30px;
        margin-left: 15px;
    }
    .header-right {
        width: 80px;
        height: 25px;
        background-color: #4c7fd8;
        margin-right: 20px;  
        border-radius: 2px;     
    }
    .header-right-s {
        width: 80px;
        height: 25px;
        margin-right: 20px;
        border-radius: 2px;
    }
    .header-text {
        font-size: 13px;
        color: #666;
    }
    .header-right-text {
        font-size: 13px;
        color: #FFF;
        text-align: center;
        line-height: 25px;       
    }
    .banner-tab {  
        width: 760px;      
        height: 30px;
        display: flex;
        flex-direction: row;
        align-items: center;
        border-bottom-style: solid;
        border-bottom-width: 1px;
        border-bottom-color: #f2f2f2;
        padding-left: 5px;
        padding-right: 5px;
              
    }
    .tab {
        width: 80px;
        height: 30px;
        display: flex;
        justify-content: center; 
        margin-left: 5px;
        margin-right: 5px;
        border-bottom-style: solid;
        border-bottom-width: 0;
        border-bottom-color: #FFF;
    }
    .tab-text {
        text-align: center;
        font-size: 12px;
        color: #666;
    }
    .tab-active {
        border-bottom-style: solid;
        border-bottom-width: 2px;
        border-bottom-color: #4c7fd8;
    }
    .content {
        padding-left: 40px;
        padding-right: 40px;
        padding-top: 10px;
        padding-bottom: 20px;
        box-sizing: border-box;
    }
    .box {
        flex: 1;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;   
        height: 40px;
        align-items: center;
    }
    .box-textarea {
        flex: 1;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;   
        height: 60px;    
        margin-top: 9px;   
    }
    .box-max {
        flex: 1;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;   
        height: 90px;
        justify-content: space-between; 
    }
    .box-max-left {
        flex: 1;
        display: flex;
    }
    .box-max-right {
        flex: 1;
        box-sizing: border-box;
        
    }
    .box-max-right-box {
        background-color: #f2f2f2;
        height: 70px;
        border-radius: 3px;
        margin-right: 70px;
        margin-top: 5px;
    }
    .box-max-left-top {
        height: 40px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        box-sizing: border-box;
        margin-right: 70px;
    }
    .box-max-left-bottom {
        height: 40px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        box-sizing: border-box;
        margin-right: 70px;
    }
    .box-text {
        font-size: 12px;
        color: #666;
    }
    .line {
        flex: 1;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        box-sizing: border-box;
        margin-right: 70px;
    }
    .line-textarea {
        flex: 1;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: flex-start;
        box-sizing: border-box;
        margin-right: 70px;
    }
    .title {
        width: 80px;
    }
    .title-textarea {
        width: 80px;
        padding-top: 8px;
    }
    .input {
        position: relative;
        flex: 1;
        box-sizing: border-box;
        padding-left: 8px;
        height: 25px;       
        border-radius: 5px;
        border-style: solid;
        border-width: 0.5px;
        border-color: #b1b1b1;
    }
    .input-text {  
        color: #666;
        line-height: 22px;     
        font-size: 12px;
    }
    .input-unit {
        position: absolute;
        color: #666;
        font-size: 12px;
        top: 4px;
        right: 8px;
    }
    .checkbox {
        width: 87px;
        height: 25px;
        background-color: #f2f2f2;
        border-radius: 3px;        
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .checkbox-auto {  
        display: flex;
        justify-content: center;
        align-items: center;      
        height: 25px;
        background-color: #f2f2f2;
        border-radius: 3px;        
        padding-left: 10px;
        padding-right: 10px;
    }
    .checkbox-active {
        background-color: #4c7fd8;
    }
    .checkbox-text {
        font-size: 12px;
        color: #666;
    }
    .checkbox-text-active {
        color: #FFF;
    }
    .mf-10 {
        margin-left: 10px;
    }
    .line-bottom {
        flex: 1;
        height: 25px;        
        background-color: #f2f2f2;
        border-radius: 3px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    .line-bottom-active {              
        background-color: #4c7fd8;       
    }
    .line-bottom-text {
        font-size: 12px;
        color: #666;
    }
    .line-bottom-text-active {        
        color: white;
    }
    .textarea {
        box-sizing: border-box;
        flex: 1;
        border-radius: 5px;
        border-style: solid;
        border-width: 0.5px;
        border-color: #b1b1b1;
        font-size: 12px;
        height: 25px; 
        padding-left: 3px;
        padding-top: 3px; 
    }
    .box-active {
        background-color: #4c7fd8;
    }
    .box-text-active {
        color: #FFF;
    }
    .img-unit {
        position: absolute;                  
        top: 3px;
        right: 5px;
        width: 8px;
        height: 16px;
    }
</style>

